import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 防止多次点击当前导航时，报“NavigationDuplicated”
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

const routes = [
  {
    path: '/',
    redirect: '/index',
    component: () => import('@/components/Whole.vue'),
    children: [
      {
        path: '/index',
        component: () => import('@/views/Home.vue'),
        meta: { title: '首页' }
      },
      {
        path: '/system',
        component: () => import('@/views/system/index.vue'),
        meta: { title: '一级菜单1' },
        redirect: '/system/user',  // 该配置是若点击选择一级菜单时，默认选中并跳转到该一级菜单下的第一个二级菜单
        children:[
          {
            path: 'user',
            component: () => import('@/views/system/user.vue'),
            meta: { title: '用户管理' },
          }
        ]
      },
    ]
  },
  {
    path: '/Login',  // 登录页面
    component: () => import('@/views/Login.vue'),
    meta: { title: '登录' }
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
